package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.dto.DishDTO;
import com.sky.dto.SetmealDTO;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Api(tags = "c端-套餐管理")
public class SetmealController {

    @Autowired
    SetmealService setmealService;

    @GetMapping("/list")
    @ApiOperation("根据分类id查询套餐")
    @Cacheable (cacheNames = "setmealCache", key = "#categoryId") // key: setmealCache::100
    public Result<List<Setmeal>> selectSetmealByCategoryId(Long categoryId) {
        Setmeal setmeal = new Setmeal();
        // 判断套餐是否为起售状态
        setmeal.setStatus(StatusConstant.ENABLE);
        setmeal.setCategoryId(categoryId);
        // 查询套餐
        List<Setmeal> list = setmealService.selectSetmealByCategoryId(setmeal);
        return Result.success(list);
    }

    @GetMapping("/dish/{id}")
    @ApiOperation("根据套餐ID查询包含的菜品")
    public Result<List<DishItemVO>> selectDishBySetmealId(@PathVariable Long id){
        SetmealDish setmealDish = new SetmealDish();
        setmealDish.setSetmealId(id);

        List<DishItemVO> list = setmealService.selectDishBySetmealId(setmealDish);
        return Result.success(list);
    }
}
